package com.heima.freemarker.controller;

import com.heima.freemarker.entity.Student;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 嘉德罗斯
 * @date 2021/11/22
 */
@Controller
public class HelloController {

    @GetMapping("/basic")
    public String basic(Model model){

        model.addAttribute("name","嘉德罗斯");

        Student student = new Student();
        student.setAge(19);
        student.setName("安迷修");

        model.addAttribute("stu",student);
        return "01-basic";
    }

    @GetMapping("/list")
    public String list(Model model){
        Student student1 = new Student();
        Student student2 = new Student();
        student1.setName("嘉德罗斯");
        student1.setAge(9);
        student1.setMoney(1000.5f);
        student2.setName("安迷修");
        student2.setAge(15);
        student2.setMoney(500.4f);
        List<Student> list = new ArrayList<>();
        list.add(student1);
        list.add(student2);
        model.addAttribute("stus",list);

        Map map = new HashMap();
        map.put("stu1",student1);
        map.put("stu2",student2);
        model.addAttribute("stuMap",map);
        return "02-list";
    }
}
